package com.sxp.dao;

import com.sxp.model.MealType;
import com.sxp.util.DBUtil;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by lakmini on 10/20/14.
 */
public class MealDaoImpl implements MealDao{

    public List<MealType> getMealList() {
        Connection conn = null;
        List<MealType> ml = new ArrayList<MealType>();

        try {
            conn = DBUtil.getConnection();
            Statement stmt = conn.createStatement();
            ResultSet rSet = stmt.executeQuery("select * from meal_type");

            while (rSet.next()) {
                MealType mt=new MealType();
                mt.setMealId(rSet.getInt("id"));
                mt.setMealType(rSet.getString("type"));
                ml.add(mt);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }finally{
            DBUtil.closeConnection(conn);
        }

        return ml;
    }
}
